const children = [];
const routes = [

    //访问路由“/”,自动重定向到"/home"
    {
        path: '/',
        redirect: '/m_login'
    },
    {
        path: '/m_login',
        name: 'M_Login',
        component: () => import('@/views/m_login.vue')
    },
    {
        path: '/m_register',
        name: 'M_Register',
        component: () => import('@/views/m_register.vue')
    },
    {
        path: '/m_home',
        name: 'M_Home',
        component: () => import('@/views/m_home/m_home.vue'),
        children: [
            {
                path: '/m_home/index',
                name: 'index',
                component: () => import('@/views/m_home/index.vue')
            },
            {
                path: '/m_home/energyManagement/createEnergy',
                name: 'createEnergy',
                component: () => import('@/views/m_home/energyManagement/createEnergy.vue')
            },
            {
                path: '/m_home/energyManagement/energyDetail',
                name: 'energyDetail',
                component: () => import('@/views/m_home/energyManagement/energyDetail.vue')
            },
            {
                path: '/m_home/userManagement/balanceManagement',
                name: 'balanceManagement',
                component: () => import('@/views/m_home/userManagement/balanceManagement.vue')
            },
            {
                path: '/m_home/userManagement/userManagement',
                name: 'userManagement',
                component: () => import('@/views/m_home/userManagement/userManagement.vue')
            },
            {
                path: '/m_home/systemSetting',
                name: 'systemSetting',
                component: () => import('@/views/m_home/systemSetting.vue')
            },
            {
                path: '/m_home/electricityManagement/electricityManagement',
                name: 'electricityManagement',
                component: () => import('@/views/m_home/electricityManagement/electricityManagement.vue')
            },
            {
                path: '/m_home/electricityManagement/meterData',
                name: 'meterData',
                component: () => import('@/views/m_home/electricityManagement/meterData.vue')
            },
        ]
    },
    {
        path: '/404',
        name: "NotFound",
        component: () => import('@/views/404.vue')
    }
];

export const existsRoute = (path) => {
    for (let i = 0; i < routes.length; i++) {
        const r = routes[i];
        if (r.path == path) {
            return true;
        }
        if (r.children && r.children.length) {
            for (let k = 0; k < r.children.length; k++) {
                const sr = r.children[k];
                if (sr.path == path) {
                    return true;
                }
            }
        }
    }
    return false;
};

export default routes;